import java.util.Arrays;

public class Stack implements IStack {

    public int[] elem;
    public int usedSize;

    public Stack() {
        this.elem = new int[10];
    }


    public boolean isFull() {
        return this.elem.length == usedSize;
    }


    public boolean isEmpty() {
        return usedSize == 0;
    }


    public void push(int data) {
        if(isFull()) {
            //如果满了就扩容
            this.elem = Arrays.copyOf(elem, 2*elem.length);
        }
        elem[usedSize++] = data;
    }


    public int pop() {
        if(isEmpty()) {
            return -1;
        }

        int tmp = elem[usedSize - 1];
        usedSize--;
        return tmp;
    }


    public int peek() {
        if(isEmpty()) {
            return -1;
        }

        return elem[usedSize - 1];
    }


    public int size() {
        return usedSize;
    }
    

}
